<template>
    <li @mouseenter="isShow=true" @mouseleave="isShow=false" :class="isShow && 'active'">
        <label>
            <input @click="updateOneChecked" type="checkbox" :checked="todo.isDone" />
            <span>{{ todo.content }}</span>
        </label>
        <button @click="deleteOneTodo" v-show="isShow" class="btn btn-danger">删除</button>
    </li>
</template>
<script lang="ts">
import { defineComponent } from 'vue';
export default defineComponent({
    name: 'Item'
})
</script>
<script lang="ts" setup>
import type { TodoData } from '@/App.vue';
import { ref } from "vue"
const isShow = ref(false)
const props = defineProps<{
    todo: TodoData,
    index: number,
    updateOneChecked(index: number): void,
    deleteOneTodo:(index:number)=>void
}>()

// 更新单个todo状态
const updateOneChecked = () => {
    props.updateOneChecked(props.index)
}

// 删除单个 todo 
const deleteOneTodo=()=>{
    props.deleteOneTodo(props.index)
}


</script>

<style lang="less" scoped>
/*item*/
li {
    list-style: none;
    height: 36px;
    line-height: 36px;
    padding: 0 5px;
    border-bottom: 1px solid #ddd;
}
li.active{
    background-color: skyblue;
}

li label {
    float: left;
    cursor: pointer;
}

li label li input {
    vertical-align: middle;
    margin-right: 6px;
    position: relative;
    top: -1px;
}

li button {
    float: right;
    margin-top: 3px;
}

li:before {
    content: initial;
}

li:last-child {
    border-bottom: none;
}
</style>